package com.xq.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xq.entity.BizOutStock;
import com.xq.exception.BusinessException;
import com.xq.response.Result02;
import com.xq.service.BizOutStockService;
import com.xq.vo.OutStockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * (BizOutStock)表控制层
 *
 * @author makejava
 * @since 2020-08-09 17:03:48
 */
@Api("发放记录功能操作")
@RestController
@RequestMapping("bizOutStock")
@CrossOrigin
public class BizOutStockController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private BizOutStockService bizOutStockService;

    /**
     * 分页查询+条件
     * @param current 当前页
     * @param size 每页的最大数量
     * @param outStockVo 条件
     * @return
     */
    @ApiOperation(value = "分页查询 带条件",notes = "查询发放记录的表")
    @PostMapping("findByPage/{current}/{size}")
    public Result02 findByPage(@PathVariable("current") Integer current,@PathVariable("size") Integer size,@RequestBody(required = false) OutStockVo outStockVo){
        System.out.println("查询条件"+outStockVo+"===");
        Page<BizOutStock> byPage = bizOutStockService.findByPage(current, size, outStockVo);
        Map<String,Object> map=new HashMap<>();
        map.put("outstock",byPage.getRecords());
        map.put("total",byPage.getTotal());
        map.put("current",byPage.getCurrent());
        map.put("size",byPage.getSize());
        return Result02.success().data(map);
    }

    /**
     * 订单回收
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "订单的回收操作",notes = "回收")
    @PutMapping("updStatus/{id}/{status}")
    public Result02 updStatus(@PathVariable("id") Integer id,@PathVariable("status") Integer status){

            Boolean aBoolean = bizOutStockService.updByStatus(id, status);
            if(aBoolean){
                return Result02.success().message("回收成功！");
            }else {
                return Result02.fail().message("回收失败！");
            }

    }

    @ApiOperation(value = "删除操作",notes = "删除订单")
    @DeleteMapping("removeOutstock/{id}")
    public Result02 removeOutstock(@PathVariable("id") Integer id){
        bizOutStockService.removeByOutstock(id);
        return Result02.success().message("删除成功！");
    }

    @ApiOperation(value = "审核操作",notes = "status=0")
    @PutMapping("updPass/{id}/{status}")
    public Result02 updPass(@PathVariable("id") Integer id,@PathVariable("status") Integer status){
        bizOutStockService.updByPass(id,status);
        return Result02.success().message("审核成功！");
    }
}